package com.lyc.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.lyc.entity.User;
import com.lyc.service.UserService;
import com.lyc.vo.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/18 21:27
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/user")
@CrossOrigin//解决跨域问题
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/selectAll")
    @ApiOperation(value = "查询所有用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",defaultValue = "1",required = true,value = "页码",dataType = "int"),
            @ApiImplicitParam(name = "PageSize",defaultValue = "2",required = true,value = "条数",dataType = "int")
    })
    public Result SelectAll(Integer currentPage,
                            Integer PageSize){
        return userService.findAll(currentPage,PageSize);
    }



    @RequestMapping("insert")
    public int insert(@RequestBody User user){
        int insert = userService.insert(user);
        return insert;
    }
    @RequestMapping("update")
    public int update(@RequestBody User user){
        int i = userService.updateById(user);
        return i;
    }
    @RequestMapping("delete")
    public int delete(int id){
        int i = userService.deleteById(id);
        return i;
    }

}